<template>
  <ych-modal
    :fullscreen="false"
    :title="title"
    :visible="visible"
    :destroyOnClose="true"
    @cancel="handleCancel">

    <dict-list ref="comp" :is-select-modal="true" :radio="radio" :groupId="groupId" @selected="handleOk"></dict-list>

    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{ $t('m.common.button.close') }}</a-button>
      <a-button key="handleClear" @click="handleClear">{{ $t('m.common.button.clear') }}</a-button>
      <a-button key="submit" type="primary" @click="handleOk">{{ $t('m.common.button.ok') }}</a-button>
    </template>
  </ych-modal>
</template>

<script>

  import DictList from '../list/DictList'

  export default {
    name: 'SelectDictDialog',
    components: {
      DictList
    },
    props: {
      groupId: {
        type: String,
        required: true
      },
    },
    data () {
      return {
        title: this.$t('m.eform.formDesign.label.xuan-ze-shu-ju-zi-dian'),
        visible: false,
        radio: false,
      }
    },
    methods: {
      handleCancel () {
        this.visible = false
        this.radio = false
      },
      handleOk () {
        if (this.$refs.comp.selectedRowKeys.length == 0) {
          this.messageUtil.warning(this.$t('m.eform.formDesign.label.qing-xuan-ze-shu-ju'))
          return
        }
        this.$emit('selectFinished', this.$refs.comp.selectedRowKeys, this.$refs.comp.selectionRows)
        this.handleCancel()
      },
      handleClear () {
        this.$emit('selectFinished')
        this.handleCancel()
      },
    }
  }
</script>
